package com.mhg.threadpool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Demo_06 {

	public static void main(String[] args) {
		//static ExecutorService newSingleThreadExecutor() 单个线程线程池
		/*
		 * 创建一个 使用单个线程的线程池
		 * 用唯一的线程来执行任务 保证所有任务能够按照顺序执行
		 * */
		ExecutorService single = Executors.newSingleThreadExecutor();
		for(int i=0;i<10;i++){
			final int index = i;
			single.execute(new Runnable() {
				
				@Override
				public void run() {
					System.out.println(Thread.currentThread().getName()+",,,"+index);
					try {
						Thread.sleep(2000);
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			});
		}
		single.shutdown();
	}

}
